


************************************************************
*-- Analyze appropriation by treatment and dev. category
************************************************************

use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2-full.dta"

*-- US All vs. Early
eststo: tobit extract1to10 tx1 if treatment_number==1 | (treatment_number==3 & early==1), ll ul cluster(groupid)
*-- China All vs. Early
eststo: tobit extract1to10 tx5 if treatment_number==5 | (treatment_number==6 & early==1), ll ul cluster(groupid)


*-- US Early vs. Late
eststo: tobit extract6to10 early if treatment_number==3, ll ul cluster(groupid)
*-- China Early vs. Late
eststo: tobit extract6to10 early if treatment_number==6, ll ul cluster(groupid)


*-- US All vs. Late
eststo: tobit extract6to10 tx1 if treatment_number==1 | (treatment_number==3 & early==0), ll ul cluster(groupid)
*-- China All vs. Late
eststo: tobit extract6to10 tx5 if treatment_number==5 | (treatment_number==6 & early==0), ll ul cluster(groupid)


*-- US All Undiff vs. Pooled Diff 
*-- these were to respond to NHB Reviewer 3, but I think the point is better illustrated by using a KS 
	*- test similar to that for the prop_contribution calculations below
*--(the & earlyy==0 is just so that it selects just one of the two observations from that group; 
*-- mean_extract6to10 is the average of the earlys' and lates' exraction over 6-10. 
eststo: tobit mean_extract6to10 tx1 if treatment_number==1 | treatment_number==3, ll ul cluster(groupid)
*-- China All Undiff vs. Pooled Diff
eststo: tobit mean_extract6to10 tx5 if treatment_number==5 | treatment_number==6, ll ul cluster(groupid)

*-- See if approporation in China is higher in each category than in the U.S.
use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2_one-per-group&dev-status.dta" 

*-- baseline US vs. baseline China
ranksum mean_total_extract_early if treatment_number==1 | treatment_number==5, by(treatment_number)

*-- early US vs. early China
ranksum mean_total_extract_early if (treatment_number==3 & early==1) | (treatment_number==6 & early==1), by(treatment_number)

*-- late US vs. late China
ranksum mean_total_extract_early if (treatment_number==3 & early==0) | (treatment_number==6 & early==0), by(treatment_number)



***********************************************************
*-- Analyze contribution by treatment and dev. category
***********************************************************

*-- want to analyze proportional contributions as we did for extraction amounts above. 
	*-- statistically simplest way is to collapse to group level and use mean contribution ratio by groupid
	*-- then, b/c this is a DV that is on the 0-1 interval, we use KS tests. 
	*-- recall that 'mean_contrib_ratio_early' is the group/subgroup avg. proportional contribution
	
use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2_one-per-group&dev-status.dta" 

*-- US Early vs. Late
ksmirnov mean_contrib_ratio_early if treatment_number==3, by(early)
*-- China Early vs. Late
ksmirnov mean_contrib_ratio_early if treatment_number==6, by(early)

*-- US All vs. Early
ksmirnov mean_contrib_ratio_early if treatment_number==1 | (treatment_number==3 & early==1), by(tx1)
*-- China All vs. Early
ksmirnov mean_contrib_ratio_early if treatment_number==5 | (treatment_number==6 & early==1), by(tx5)

*-- US All vs. Late
ksmirnov mean_contrib_ratio_early if treatment_number==1 | (treatment_number==3 & early==0), by(tx1)
*-- China All vs. Late
ksmirnov mean_contrib_ratio_early if treatment_number==5 | (treatment_number==6 & early==0), by(tx5)


use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2_one-per-group.dta"

*-- US All Undiff vs. Pooled Diff
ksmirnov mean_contrib_ratio if treatment_number==1 | treatment_number==3, by(tx1)
*-- China All Undiff vs. Pooled Diff
ksmirnov mean_contrib_ratio if treatment_number==5 | treatment_number==6, by(tx5)




*************************************************************************
*-- Three dimensions of success: met_threshold; contrib_ratio; efficiency
*************************************************************************

use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2_one-per-group.dta"


*-- non-parametric chi-squared test to determine whether End- and Ex- conditions have the same rates of met_threshold
tabulate met_threshold endogenous if treatment_number < 5, chi2	

*-- data related to the means and standard errors from the data used in this test is pasted into 3-types-of-success.csv
	*-- this data is then used to constrct Figure S1.a
		
estpost summarize contrib_ratio if treatment_number==3 & early==1
esttab ., cells("mean sd count") noobs

*-- test to determine whether End- and Ex- conditions have the same levels of proportional contributions
gen group_contrib_ratio = group_contrib/group_endow
ksmirnov group_contrib_ratio if treatment_number < 5, by(endogenous)
	*-- data from the test is pasted into 3-types-of-success.csv
		*-- this data is then used to constrct Figure S1.b
		
estpost summarize group_contrib_ratio if endogenous==0
esttab ., cells("mean sd count") noobs

estpost summarize group_contrib_ratio if endogenous==1
esttab ., cells("mean sd count") noobs


ksmirnov earnings_efficiency if treatment_number < 5, by(endogenous)
	*-- data from the test is pasted into 3-types-of-success.csv
		*-- this data is then used to constrct Figure S1.c

estpost summarize earnings_efficiency if endogenous==0
esttab ., cells("mean sd count") noobs

estpost summarize earnings_efficiency if endogenous==1
esttab ., cells("mean sd count") noobs

		
clear


****************************************************************
*-- Marginal effect of early and 'early' giving on success
****************************************************************


use "/Users/Reuben/Dropbox/Climate game/Data&Analysis/SBU-x4-Shanghai-x2-full.dta"


**-- Results of logistic models which test whether contributions *by early members* predict success; thus we test an interaction effect
	**-- "logistic" command gives output in terms of odds ratios, not log odds

	**- US: end-asym
logistic met_threshold i.early##c.contrib_ratio if treatment_number==3, cluster(groupid)

	**- US: ex-asym
logistic met_threshold i.early##c.contrib_ratio if treatment_number==4, cluster(groupid)

	**- China: end-asym	
logistic met_threshold i.early##c.contrib_ratio if treatment_number==6, cluster(groupid)
	**- this result is not part of the plot but may be mentioned in a footnote.

*-- logit coefficients need to be exponentiated, but we need to run these with "logit" so we can run "margins" afterward

logit met_threshold i.early##c.contrib_ratio if treatment_number==3, cluster(groupid)
*-- this gives us the marginals effect of early at each level of contrib_ratio from 0 to 1 by 0.1 increments
margins, dydx(early) at(contrib_ratio=(0(.1)1))
marginsplot, recast(line) recastci(rarea) yline(0)

logit met_threshold i.early##c.contrib_ratio if treatment_number==4, cluster(groupid)
*-- this gives us the marginals effect of early at each level of contrib_ratio from 0 to 1 by 0.1 increments
margins, dydx(early) at(contrib_ratio=(0(.1)1))
marginsplot, recast(line) recastci(rarea) yline(0)

	*-- this isn't really necessary b/c we don't include it in the S3 plot
logit met_threshold i.early##c.contrib_ratio if treatment_number==6, cluster(groupid)
*-- this gives us the marginals effect of early at each level of contrib_ratio from 0 to 1 by 0.1 increments
margins, dydx(early) at(contrib_ratio=(0(.1)1))
marginsplot, recast(line) recastci(rarea) yline(0)
